<template>
	<!-- 登录 -->
	<view class="container">
		<view class="title">欢迎登陆</view>
		<view class="subtitle">至真生活馆医师平台</view>

		<view class="input-container">
			<view class="input-wrapper">
				<text class="input-icon">👤</text>
				<input class="input" placeholder="请输入登录账户" id="loginAccount" v-model="username" />
			</view>
			<view class="input-wrapper">
				<text class="input-icon">🔒</text>
				<input class="input" type="password" placeholder="请输入密码" v-model="password" />
				<text class="eye-icon">👁</text>
			</view>
		</view>

		<view class="login-button" @click="goindex">登录</view>

		<view class="agreement">
			登录即视为同意 <text class="link">《用户协议》</text> <text class="link">《隐私政策》</text>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		methods: {
			goindex() {
				const data = {
					account: this.username,
					password: this.password,
				};


				const token = '5838409a-4f3c-47b9-b5c0-a6b7fcb7ebb1';


				// 发送 POST 请求给后端接口
				fetch('http://59.110.166.212/medic/physician/login', {
						method: 'POST',
						headers: {
							'Content-Type': 'application/json',
							'Authorization': 'Bearer ' + token // 在请求头中添加 Authorization
						},
						body: JSON.stringify(data)
					})
					.then(response => {
						if (!response.ok) {
							throw new Error('Network response was not ok');
						}
						return response.json();
					})
					.then(data => {
						console.log(data.code); // 处理返回的数据
						if (data.code == "1") {
							this.$refs.uToast.show({
								message: '登陆成功', // 设置提示信息的内容
								duration: 3000, // 设置提示信息显示的持续时间，单位为毫秒
							})
							uni.switchTab({
								url: "/pages/index/index"
							})
							this.username=""
							this.password=""

						} else {

							this.$refs.uToast.show({
								message: '账号密码错误', // 设置提示信息的内容
								duration: 3000, // 设置提示信息显示的持续时间，单位为毫秒
							})
							this.username=""
							this.password=""
						}
					})
					.catch(error => {
						console.error('Error:', error);
					});
				// if()
				// uni.switchTab({
				// 	url:"/pages/index/index"
				// })
				 

				console.log('用户名:', this.username);
				console.log('密码:', this.password);
			}
		},

		data() {
			return {
				show: false,
				username: '', // 存储用户名
				password: '' // 存储密码
			};
		},
	};
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 200rpx;
		background-color: #f6f6f6;
		height: 100%;
	}

	.title {
		width: 277rpx;
		height: 96rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 400;
		font-size: 69rpx;
		color: #5A4E39;
		line-height: 96rpx;
		text-align: left;
		font-style: normal;
	}

	.subtitle {
		width: 279rpx;
		height: 38rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 300;
		font-size: 27rpx;
		color: #5A4E39;
		line-height: 38rpx;
		letter-spacing: 2px;
		text-align: left;
		font-style: normal;
	}

	.input-container {
		width: 80%;
		margin-top: 100rpx;
	}

	.input-wrapper {
		display: flex;
		align-items: center;
		background-color: #ffffff;
		border-radius: 50rpx;
		padding: 0 20rpx;
		margin-bottom: 20rpx;
	}

	.input-icon,
	.eye-icon {
		font-size: 36rpx;
		color: #909090;
		margin-right: 10rpx;
	}

	.input {
		flex: 1;
		height: 100rpx;
		font-size: 30rpx;
		border: none;
		outline: none;
	}

	.login-button {
		width: 80%;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-image: linear-gradient(to right, #BAA070, #CEB688);
		border-radius: 50rpx;
		color: #ffffff;
		font-size: 36rpx;
		font-weight: bold;
		margin-top: 50rpx;
	}

	.agreement {
		font-size: 24rpx;
		color: #909090;
		margin-top: 350rpx;
	}

	.link {
		color: #BAA070;
		text-decoration: underline;
		margin-left: 5rpx;
	}
</style>